var _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(t) {
    return typeof t;
  } : function(t) {
    return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol.prototype ? "symbol" : typeof t;
  },
  is_no_more = !1,
  is_loading_more = !1;

Page({
  data: {
    cat_list: [],
    sub_cat_list_scroll_top: 0,
    scrollLeft: 0,
    page: 1,
    cat_style: 0,
    height: 0,
    catheight: 120,
    current_8_index: 0,
    current_8_2_index: 0,
    current: 0,
    tab1: 0,
    tab2: 0,
    tab3: -1,
    goods_list: [],
    is_no_more: !1,
    first_name:"课程"
  },
  onLoad: function(t) {
    var a = this;
    console.log(t);
    getApp().page.onLoad(a, t);
    
    this.loadData()
  },
  currentClick: function (e) {
    var that = this;
    var current = that.data.current == 2 ? '':e.currentTarget.dataset.current;
    that.setData({
      current: current
    })

  },
  selectClick: function (e) {
    var that = this;
    var type = e.currentTarget.dataset.type;
    console.log(type)
    if(type == 1) {
      
      var tab1 = e.currentTarget.dataset.tab1;
      that.setData({
        tab1: tab1,
        first_name: tab1==1 ? '课程' : '机构'
      })
    }else if(type == 2) {
      var tab2 = e.currentTarget.dataset.tab2;
      that.setData({
        tab2: tab2,
        tab3: -1,
        cat_id: that.data.cat_list[tab2].id,
        cat_name: that.data.cat_list[tab2].name
      });
      var children_cat_list = that.data.cat_list[tab2].list;
      that.setData({
        children_cat_list: children_cat_list
      })
    }else{
      var tab3 = e.currentTarget.dataset.tab3;
      that.setData({
        tab3: tab3,
        cat_id:  that.data.children_cat_list[tab3].id,
        cat_name: that.data.children_cat_list[tab3].name
      })
    }
    that.setData({
      page:1,
      is_no_more: !1,
      goods_list: [],
      current:0
    }),that.loadMoreGoodsList();
  },
  navigatorGoods:function(e){
    getApp().core.navigateTo({
      url: '/pages/goods/goods?id=' + e.currentTarget.dataset.id
    });
  },
  close: function () {
    this.setData({
      current: ''
    })
  },
  onShow: function() {
    var that = this;
    if(wx.getStorageSync("cat_id")&&that.data.cat_list.length>0){
      console.log(that.data.cat_list)
        var catIndex = 0;
        for(let i= 0; i < that.data.cat_list.length; i++) {
          // catIndex++;
          if(that.data.cat_list[i].id == wx.getStorageSync("cat_id")){
            catIndex=i;
            console.log(catIndex)
            break
          }
          
        }
        that.setData({
          tab2:catIndex,
          tab3: -1,
          cat_name: that.data.cat_list[catIndex].name,
          page:1,
          is_no_more: !1,
          goods_list: [],
          current:0,
          cat_id:that.data.cat_list[catIndex].id,
          children_cat_list: that.data.cat_list[catIndex].list
        }),that.loadMoreGoodsList()
        console.log(wx.getStorageSync("cat_id"),catIndex)
    }
    
  },  
  
  onReachBottom: function() {
    getApp().page.onReachBottom(this);
    is_no_more || 5 != getApp().core.getStorageSync(getApp().const.STORE).cat_style && -1 != this.data.cat_style || this.loadMoreGoodsList();
  },
  loadData: function() {
    var a = this;
      getApp().core.showLoading({
        title: "正在加载",
        mask: !0
      })
      getApp().request({
        url: getApp().api.default.cat_list,
        success: function(res) {
          if (res.code == 0) {
            if(wx.getStorageSync("cat_id")){
              a.setData({
                cat_list: res.data.list,
                page:1,
                is_no_more: !1,
                goods_list: [],
                current:0
              })
              console.log(res.data.list)
              var catIndex = 0;
              for(let i = 0; i < a.data.cat_list.length; i++) {
                // catIndex++
                if(a.data.cat_list[i].id == wx.getStorageSync("cat_id")){
                  
                  catIndex=i;
                  console.log(catIndex)
                  break;
                }
                
              }
              a.setData({
                tab2:catIndex,
                tab3:-1,
                cat_name: a.data.cat_list[catIndex].name,
                cat_id: a.data.cat_list[catIndex].id,
                children_cat_list: a.data.cat_list[catIndex].list
              }),a.loadMoreGoodsList();
              console.log(a.data.cat_list[catIndex].name,catIndex)
            }else{
              a.setData({
                tab3:-1,
                cat_list: res.data.list,
                cat_id: res.data.list[0].id,
                cat_name: res.data.list[0].name,
                children_cat_list: res.data.list[0].list
              }),a.loadMoreGoodsList();
            }
          }
        },
        complete: function () {
          getApp().core.hideLoading()
        }
      })
     
  },
  loadMoreGoodsList: function() {
    var e = this;
    if (!is_loading_more) {
      
      var t = e.data.cat_id || "",
        o = e.data.page || 1;
      var shop_id = wx.getStorageSync('address_info').shop_id
      getApp().request({
        url: getApp().api.default.goods_list,
        data: {
          page: o,
          cat_id: t,
          shop_id: shop_id
        },
        success: function(t) {
          0 == t.data.list.length && e.setData({is_no_more: !0});
          var a = e.data.goods_list.concat(t.data.list);
          console.log(e.data.tab3)
          e.setData({
            goods_list: a,
            page: o + 1,
            page_count: t.data.page_count
          });
        },
        complete: function() {
          wx.getStorageSync("cat_id")&&wx.removeStorageSync("cat_id");
          
        }
      });
    }
  },
  
 
 
  resetData: function () {
    this.setData({
      checked_attr: [],
      check_num: 0,
      check_goods_price: 0,
      temporaryGood: {
        price: "0.00"
      }
    });
  }
 
});